package com.springboot.myweb.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2
public class SwaggerConfig {


    @Bean
    public Docket docket(Environment environment){
        //检测是不是开发环境
        Profiles profiles = Profiles.of("dev");
        boolean b = environment.acceptsProfiles(profiles);
        return  new Docket(DocumentationType.SWAGGER_2)
                .enable(b)
                .apiInfo(apiInfo())
                .select()
                //接口扫描方式
                /**
                 * basePackage指定扫描的包
                 *withClassAnnoation 扫描类上的注解
                 *withMethodAnnoation 扫描方法上的注解
                 */
                .apis(RequestHandlerSelectors.basePackage("com.springboot.myweb.controller"))
                .build();
    }


    private ApiInfo apiInfo(){
        Contact contact = new Contact("deeeelete","http://localhost","deeeelete@qq.com");

        return  new ApiInfo("Deeeelete", "Api Documentation", "1.0", "urn:tos", contact, "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", new ArrayList());
    }
}
